import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export const publicRoutes=[
        {
            path:"/login",
            component:(resolve) => require(["@/views/login"],resolve),
            meta:{
                loginRequest:false
            }
        },
        {
            path:"/register",
            component:(resolve) => require(["@/views/indexPage/users/register"],resolve),
            meta:{
                loginRequest:false
            }
        },
        {
            path:"/test",
            component:(resolve) => require(["@/views/indexPage/test"],resolve),
        },
        {
            path:"/videoPlay/:divState/:videoId",
            component:(resolve) => require(["@/views/indexPage/video/videoPlay"],resolve),
            meta:{
                loginRequest:true
            }
        },
        {
            path:"/detail/:divState/:articleId",
            component:(resolve) => require(["@/views/detailBar"],resolve),
            meta:{
                loginRequest:false
            }
        },
        {
            path:"/index",
            alias:"/",
            component:(resolve) => require(["@/views/indexPage/index"],resolve),
            children:[
                {
                    path:"/creator/:usersId",
                    alias:"creator",
                    component:(resolve) => require(["@/views/indexPage/users/creator"],resolve),
                    meta:{
                        loginRequest:true
                    }
                },
                {
                    path:"/collectArticle/:collectName/:collectId",
                    alias:"collectArticle",
                    component:(resolve) => require(["@/views/indexPage/article/collectArticle"],resolve),
                    meta:{
                        loginRequest:true
                    }
                },
                {
                    path:"/messageCenter",
                    component:(resolve) => require(["@/views/indexPage/messageCenter/messageOption"],resolve),
                    //这里出现白屏未报错的情况下只需将父路由后斜杠和子路由的前斜杠去掉即可
                    children: [
                        {
                            path:"comment",
                            component:(resolve) => require(["@/views/indexPage/messageCenter/informReplyComment"],resolve),
                            meta:{
                                loginRequest:true
                            }
                        },
                        {
                            path:"chat",
                            component:(resolve) => require(["@/views/indexPage/messageCenter/chat"],resolve),
                            children: [
                                {
                                    path: ":key/:usersId",
                                    component:(resolve) => require(["@/views/indexPage/messageCenter/chatContent"],resolve),
                                }
                            ],
                            meta:{
                                loginRequest:true
                            }
                        }
                    ],
                    meta:{
                        loginRequest:true
                    },
                },
                {
                    path:"searchArticle",
                    alias:"searchArticle",
                    component:(resolve) => require(["@/views/indexPage/article/searchArticle"],resolve),
                    meta:{
                        loginRequest:true
                    }
                },
                {
                    path:"options",
                    alias:"/",
                    component:(resolve) => require(["@/views/indexPage/options"],resolve),
                    children:[
                        {
                            path:"articleOption",
                            alias:"/",
                            component:(resolve) => require(["@/views/indexPage/article/articleOption"],resolve),
                            children:[
                                {
                                    path:"recommend",
                                    alias:"/",
                                    component:(resolve) => require(["@/views/indexPage/article/recommend"],resolve),
                                    meta:{
                                        loginRequest:true
                                    }
                                },
                                {
                                    path:"focus",
                                    alias:"focus",
                                    component:(resolve) => require(["@/views/indexPage/article/focusUsersDynamic"],resolve),
                                    meta:{
                                        loginRequest:true
                                    }
                                },
                                {
                                    path:"hot",
                                    alias:"hot",
                                    component:(resolve) => require(["@/views/indexPage/article/hotList"],resolve),
                                    meta:{
                                        loginRequest:true
                                    }
                                }
                            ],
                            meta:{
                                loginRequest:true
                            }
                        },
                        {
                            path:"community",
                            alias:"community",
                            component:(resolve) => require(["@/views/indexPage/community/communityOption"],resolve),
                            meta:{
                                loginRequest:true
                            }
                        },
                        {
                            path: "video",
                            alias: "video",
                            component:(resolve) => require(["@/views/indexPage/video/recommendVideo"],resolve),
                            meta:{
                                loginRequest:true
                            }
                        }
                    ],
                    meta:{
                        loginRequest:true
                    }
                },
                {
                    path:"/userHome/:usersId",
                    component:(resolve) => require(["@/views/indexPage/users/message/usersMessage"],resolve),
                    children:[
                        {
                            path: "dynamic",
                            alias:"/",
                            component:(resolve) => require(["@/views/indexPage/users/message/msgDynamic"],resolve),
                            meta:{
                                loginRequest:true
                            }
                        },
                        {
                            path: "/attention/:usersId",
                            alias: "attention",
                            component:(resolve) => require(["@/views/indexPage/users/message/msgAttention"],resolve),
                            meta:{
                                loginRequest:true
                            }
                        },
                        {
                            path: "/collect/:usersId",
                            alias: "collect",
                            component:(resolve) => require(["@/views/indexPage/users/message/msgCollect"],resolve),
                            meta:{
                                loginRequest:true
                            }
                        }
                    ],
                    meta:{
                        loginRequest:true
                    }
                },
                {
                    path:"userUpdate",
                    component:(resolve) => require(["@/views/indexPage/users/usersUpdate"],resolve),
                    meta:{
                        loginRequest:true
                    }
                },
                {
                    path:"writeArticle",
                    alias:"writeArticle",
                    component:(resolve) => require(["@/views/indexPage/article/writeArticle"],resolve),
                    meta:{
                        loginRequest:true
                    }
                },
                {
                    path:"postVideo",
                    alias:"postVideo",
                    component:(resolve) => require(["@/views/indexPage/video/createVideo"],resolve),
                    meta:{
                        loginRequest:true
                    }
                },
            ],
            meta:{
                loginRequest:true
            }
        }
]

export default new Router({
    mode: 'history', // 去掉url中的#
    routes: publicRoutes
})

const originalPush = Router.prototype.push
//修改原型对象中的push方法
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}
